#include "../../native_shm.h"
#include "../../dfruntime.h"
#include "../../global_queue.h"
#include "../../asyncpages.h"
#include "../../memory_management.h"
#include "../../page_management.h"

#include <omp.h>



int rmain(int argc, char ** argv ) {


	void* glob = dfrt_mem_get_global();
	//Compete for a ressource :
 
  for ( int i = 0; i < 1000;++i) {

#pragma omp task
    {

      printf( "Will acquire 20...(%d)\n", dfrt_whoami() );
	    sync_safe_acquire( glob+20, 8, true);
      // Check that page is acquired..
      if ( NULL == page_is_acquired( glob+20) ) {
        DEBUG( "Alarm : the page was acquired and is not registered as such...");
      }
  	    safe_release_page( glob+20 );
	    sync_safe_acquire( glob+40, 10, true);
  	  safe_release_page( glob+40 );
    }
  }	
	printf("ATTACKING QUEUE!, from %d\n", dfrt_whoami());
  printf("%d initialized queue successfully.\n", dfrt_whoami());

}


int main() {
  dfrt_init(2,2, rmain);
}
